#!/usr/bin/env python3.6
# -*- encoding: utf-8 -*-
'''
@File    :   serializersModels.py
@Time    :   2020/04/12 15:44:26
@Author  :   Tang Jing 
@Version :   1.0.0
@Contact :   yeihizhi@163.com
@License :   (C)Copyright 2020
@Desc    :   None
'''

# here put the import lib

# django import lib
from django.core.exceptions import ValidationError
from django.db.models import Q
from rest_framework import status
# project import lib
from api.models import *
from api.restframework.baseSerializers import *

# code start
class categorySerializer(serializers.ModelSerializer):

    def enable(self,pk, validated_data):
        try:
            category.objects.filter(Q(id__exact= pk) | Q(parent_id__exact= pk)).update(enable= validated_data.get('enable'))
            return True
        except Exception as e:
            return False

    class Meta:
        model= category
        fields= '__all__'

class movieSerializer(serializers.ModelSerializer):
    class Meta:
        model= movie_list
        fields= '__all__'
    
    '''
    category= serializers.SerializerMethodField()
    def get_category(self, obj):
        author_list_values = []
        author_dict = {}
        author_list = obj.authors.all()
        for i in author_list:
            author_dict['name'] = i.name
            author_list_values.append(author_dict)
        return author_list_values
    '''

class playUrlSerializer(serializers.ModelSerializer):
    class Meta:
        model= movie_play_list
        fields= '__all__'